package com.icongyou.enterprise.talent_pool.scheduler;

import com.icongyou.enterprise.talent_pool.service.AssignmentTagService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RequiredArgsConstructor
public class AssignmentTagScheduler implements CommandLineRunner {

    private final AssignmentTagService assignmentTagService;

    /**
     * 每天凌晨2点执行任务-标签关联计算
     */
    @Scheduled(cron = "0 0 2 * * ?")
    public void scheduledAssignmentTagCalculation() {
        try {
            assignmentTagService.calculateAssignmentTagAssociations();
        } catch (Exception e) {
        }
    }

    /**
     * 服务器启动后立即执行一次初始计算
     */
    @Override
    public void run(String... args) throws Exception {
        try {
            assignmentTagService.calculateAssignmentTagAssociations();
        } catch (Exception e) {
        }
    }
}